package org.lds.hotkey.console.business.rule.controller;

import lombok.extern.slf4j.Slf4j;
import org.lds.hotkey.common.model.dto.ResultDTO;
import org.lds.hotkey.common.model.pojo.OrderBy;
import org.lds.hotkey.common.model.pojo.PageResult;
import org.lds.hotkey.console.business.rule.model.request.*;
import org.lds.hotkey.console.business.rule.model.response.*;
import org.lds.hotkey.console.business.rule.service.RuleBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础前端控制器
 *
 * @author lidongsheng
 * @since 2024-06-05
 */
@Slf4j
@RestController
@RequestMapping("/api/common/rule")
public class RuleBaseController {

    @Autowired
    private RuleBaseService ruleBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<RuleBaseResponse> createRule(@RequestBody @Validated RuleBaseCreateRequest request) {
        return ruleBaseService.createRule(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<RuleBaseBatchCreateResponse> batchCreateRule(@RequestBody @Validated RuleBaseBatchCreateRequest request) {
        return ruleBaseService.batchCreateRule(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<RuleBaseDeleteResponse> deleteRule(@RequestBody RuleBaseDeleteRequest request) {
        return ruleBaseService.deleteRule(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<RuleBaseBatchDeleteResponse> batchDeleteRule(@RequestBody @Validated RuleBaseBatchDeleteRequest request) {
        return ruleBaseService.batchDeleteRule(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<RuleBaseResponse> updateRule(@RequestBody @Validated RuleBaseUpdateRequest request) {
        return ruleBaseService.updateRule(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<RuleBaseBatchUpdateResponse> batchUpdateRule(@RequestBody @Validated RuleBaseBatchUpdateRequest request) {
        return ruleBaseService.batchUpdateRule(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<RuleBaseListResponse> listRule(@RequestBody RuleBaseListRequest request) {
        return ruleBaseService.listRule(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<RuleBaseListResponse> listAllRule(@RequestBody OrderBy orderBy) {
        return ruleBaseService.listAllRule(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<RuleBaseResponse> getRuleById(@RequestBody @Validated RuleBaseGetByIdRequest request) {
        return ruleBaseService.getRuleById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<RuleBaseListResponse> getRuleByIds(@RequestBody @Validated RuleBaseGetByIdsRequest request) {
        return ruleBaseService.getRuleByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<RuleBaseResponse>> listRulePage(@RequestBody RuleBaseListPageRequest request) {
        return ruleBaseService.listRulePage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated RuleBaseGetByKeyRequest request) {
        return ResultDTO.success(ruleBaseService.getRuleByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<RuleBaseBatchCreateResponse> batchCreateRuleAsync(@RequestBody @Validated RuleBaseBatchCreateRequest request) {
        return ruleBaseService.batchCreateRuleAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<RuleBaseBatchDeleteResponse> batchDeleteRuleAsync(@RequestBody @Validated RuleBaseBatchDeleteRequest request) {
        return ruleBaseService.batchDeleteRuleAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<RuleBaseBatchUpdateResponse> batchUpdateRuleAsync(@RequestBody @Validated RuleBaseBatchUpdateRequest request) {
        return ruleBaseService.batchUpdateRuleAsync(request);
    }

}